/*
 * Copyright (c) 2019.
 * Project: report
 * File : BuildinDataSource
 * Author: Jimmy Chou
 * Mail: zhou.guangjie123@ztesoft.com
 * Date: 2019-03-30 16:46:22
 */

package com.zjh.datasource;

import com.bstek.ureport.definition.datasource.BuildinDatasource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * Created by Jimmy Chou on 2019-03-30 16:46:21
 */
@Configuration
public class BuildInDataSource implements BuildinDatasource {

    private static final Logger logger = LoggerFactory.getLogger(BuildInDataSource.class);

    @Autowired
    private DataSource dataSource;
    private String name;

    public BuildInDataSource() {
        this.name = "iyunwen-robot";
    }

    @Override
    public String name() {
        return this.name;
    }

    @Override
    public Connection getConnection() {
        try {
            return this.dataSource.getConnection();
        } catch (SQLException e) {
            logger.error(e.getMessage());
            return null;
        }
    }
}
